package com.totoro.service.impl;

import com.totoro.mapper.AttributeMapper;
import com.totoro.mapper.ProductMapper;
import com.totoro.pojo.*;
import com.totoro.service.AttributeService;
import com.totoro.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
 * @author TOTORO
 * @date 2021/6/14 15:47
 */
@Service
public class AttributeServiceImpl implements AttributeService {

    @Autowired
    AttributeMapper attributeMapper;
    @Autowired
    ProductMapper productMapper;

    @Override
    public List<SpuKey> findSpu(int id) {
        return attributeMapper.findSpu(id);
    }

    @Override
    public String findSpuValue(int akid) {
        return attributeMapper.findSpuValue(akid);
    }

    @Override
    public List<SkuKey> findSkuListById(int cid) {
        List<SkuKey> list = attributeMapper.findSkuListById(cid);
        list.sort(Comparator.comparing(SkuKey::getKeySort).reversed());
        return list;
    }

    @Override
    public List<ProductSpecs> findProductSkusById(int pid) {
        return productMapper.findProductSkusById(pid);
    }

    @Override
    public Integer updateProductSkuAttr(ProductSpecs productSpecs) {
        return attributeMapper.updateProductSkuAttr(productSpecs);
    }
}
